package com.example.mypotiota_si.Adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.mypotiota_si.Datas.XueXiao;
import com.example.mypotiota_si.R;

import java.util.ArrayList;

public class ListViewAdapter_school extends RecyclerView.Adapter<ListViewAdapter_school.ViewHolder> {
    ArrayList<XueXiao> xueXiao;
    public ListViewAdapter_school(ArrayList<XueXiao> xueXiao) {
        this.xueXiao = xueXiao;
    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.item_school_list_view,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.setData(xueXiao.get(position));
    }

    @Override
    public int getItemCount() {
        if (xueXiao!=null) {
            return xueXiao.size();
        }
        return 0;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
            private TextView school_name;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            school_name=itemView.findViewById(R.id.school_name);
        }

        public void setData(XueXiao xueXiao) {
            school_name.setText(xueXiao.school_name);
        }
    }
}
